package com.winz.cultureapp.utils;

import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;

/**
 *
 */
public class VserionNameUtil {

	/**
	 * 获取版本号
	 *
	 * @param context
	 *            上下文
	 * @return
	 * @throws NameNotFoundException
	 */
	public static Integer getVersionCode(Context context) {
		// 获取packagemanager的实例
		PackageManager packageManager = context.getPackageManager();
		// getPackageName()是你当前类的包名，0代表是获取版本信息
		PackageInfo packInfo = null;
		Integer version = 0;

		try {
			packInfo = packageManager.getPackageInfo(context.getPackageName(), 0);
			version = packInfo.versionCode;
		} catch (NameNotFoundException e) {
			e.printStackTrace();
		}
		return version;
	}
	/**
	 * 获取版本名字
	 *
	 * @param context
	 *            上下文
	 * @return
	 * @throws NameNotFoundException
	 */
	public static String getVersionName(Context context) {
		// 获取packagemanager的实例
		PackageManager packageManager = context.getPackageManager();
		// getPackageName()是你当前类的包名，0代表是获取版本信息
		PackageInfo packInfo;

		try {
			packInfo = packageManager.getPackageInfo(context.getPackageName(), PackageManager.GET_CONFIGURATIONS);
			return packInfo.versionName;
		} catch (NameNotFoundException mE) {
			mE.printStackTrace();
			return "";
		}


	}
	/**
	 * 从清单文件里面获取渠道id
	 * 
	 * @param context
	 * @return
	 * @throws NameNotFoundException
	 */
	public static String getQuDaoId(Context context) throws NameNotFoundException
	{
		
		String quDaoId="";
		ApplicationInfo appInfo = context.getPackageManager().getApplicationInfo(context.getPackageName(), PackageManager.GET_META_DATA);
		quDaoId = appInfo.metaData.getString("UMENG_CHANNEL");		
		return quDaoId;
	}

}

















